import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "SaveBookServlet", value = "/SaveBookServlet")
public class SaveBookServlet extends HttpServlet {

    private BookDao bdao = new BookDao();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json;charset=utf-8");

        String id = request.getParameter("id");
        String name = request.getParameter("bookname");
        String press = request.getParameter("bookpress");
        String date = request.getParameter("pressdate");
        String author = request.getParameter("bookauthor");
        String count = request.getParameter("bookcount");
        String image = request.getParameter("bookimage");
        try {
            bdao.save(id, name, press, date, author,
                    count, image);
            response.getWriter().print("保存成功");
        }catch (Exception e){
            response.getWriter().print("保存失败");
        }


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
